package com.hlkj.pay.vo.admin.resp.permission;

import javax.validation.constraints.NotNull;

import org.springframework.util.StringUtils;

import com.hlkj.framework.common.util.json.JsonUtils;
import com.hlkj.pay.vo.BaseMerchantResp;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
 * @author HlpayTeam
 * @date 2024/09/06 9:36
 */
@Data
public class PermissionDetailResp extends BaseMerchantResp implements Comparable<PermissionDetailResp>{
    
    /**
     * 权限code
     */
    @Schema(description = "权限code")
    private String code;
    
    /**
     * 父权限code
     */
    @Schema(description = "父权限code")
    // @NotBlank(message = "父权限code 不能为空")
    private String parentCode;
    
    
    /**
     * 权限类型： 1 模块 2 菜单 3 按钮
     * @see AdminPermissionEnum.PERMISSION_TYPE
     */
    @Schema(description = "权限类型： 1 模块 2 菜单 3 按钮")
    @NotNull
    private Integer type;
    /**
     * 路由名称
     */
    @Schema(description = "路由名称")
    // @NotBlank(message = "路由名称 不能为空")
    private String name;
    /**
     * 路由地址
     */
    @Schema(description = "路由地址")
    // @NotBlank(message = "默认路由名称 不能为空")
    private String path;
    /**
     * 默认路由名称
     */
    @Schema(description = "默认路由名称")
    // @NotBlank(message = "默认路由名称 不能为空")
    private String redirect;
    /**
     * 组件路径
     */
    @Schema(description = "组件路径")
    // @NotBlank(message = "组件路径 不能为空")
    private String component;
    
    /**
     * 接口请求对应的url
     */
    @Schema(description = "接口请求对应的url")
    private String url;
    
    /**
     * 权限标识，对应按钮级别
     */
    @Schema(description = "权限标识")
    private String perms;

    
    @Schema(description = "排序")
    private Integer sort;
    @Schema(description = "meta")
    private Meta meta;
    
    private String metaInfo;
    
    public void processMeta() {
        if(meta==null&& StringUtils.hasText(this.metaInfo)){
            setMeta(JsonUtils.parseObject(this.metaInfo,Meta.class));
        }
    }
    public static void main(String[] args) {
        String json="{\"title\":\"测试菜单update\",\"icon\":\"https://gips3.baidu.com/it/u=1821127123,1149655687&fm=3028&app=3028&f=JPEG&fmt=auto?w=720&h=1280\",\"sort\":null,\"isRoot\":1,\"disabled\":1,\"hidden\":1,\"keepAlive\":1,\"frameSrc\":\"www.baidu.com\"}";
        
        System.out.println(JsonUtils.parseObject(json,Meta.class));
    }
    @Override
    public int compareTo(@org.jetbrains.annotations.NotNull PermissionDetailResp o) {
        if(o.getSort()==null){
            o.setSort(0);
        }
        if (this.getSort() == null) {
            this.setSort(0);
        }
        return this.getSort()-o.getSort();
    }
}
